home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Science
/
RLaB
/
rlib
/
sign.r
< prev
next >
Wrap
Text File
|
1994-04-25
|
654b
|
34 lines
//-------------------------------------------------------------------//
//
// 1st cut at sign function
// Return 1, if element >= 0
// Return 0, if element == 0
// Return -1, if element < 0
//
// Does not handle complex quantities like MATLAB
//
sign = function ( a )
{
local(i, j, r);
if (class (a) != "num") { error ("sign() requires NUMERIC arg"); }
if (type (a) == "complex")
{
return a ./ abs(a);
}
r = zeros( size (a) );
for(i in 1:size (a)[1])
{
for(j in 1:size (a)[2])
{
if(a[i;j] > 0) { r[i;j] = 1; }
if(a[i;j] == 0) { r[i;j] = 0; }
if(a[i;j] < 0) { r[i;j] =-1; }
}
}
return r;
};